package com.smartbone.compenent;

import java.io.IOException;
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.log4j.Logger;

import com.smartbone.compenent.base.BasePage;
import com.smartbone.util.SecurityUtils;

@ManagedBean(name = "topForm")
@SessionScoped
public class TopForm extends BasePage implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6888295160128825927L;

	protected final Logger log = Logger.getLogger(TopForm.class);

	private String username;

	private boolean login = false;

	public String getUsername() {
		username = SecurityUtils.getUsername();
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public boolean isLogin() {
		login = SecurityUtils.isLogin();
		return login;

	}

	public void setLogin(boolean login) {
		this.login = login;
	}

	public String logoutAction() throws IOException, ServletException {
		// /j_spring_security_logout
		ExternalContext context = FacesContext.getCurrentInstance()
				.getExternalContext();
		RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
				.getRequestDispatcher("/j_spring_security_logout");
		dispatcher.forward((ServletRequest) context.getRequest(),
				(ServletResponse) context.getResponse());
		this.setLogin(false);
		this.setUsername("");
		FacesContext.getCurrentInstance().responseComplete();
		return null;
	}

	public String goLogin() {

		return "goLogin";
	}

	public String goRegiste() {

		return "goRegiste";
	}
	
	public String goUserList() {

		return "goUserList";
	}
}